class CanceladasController < ApplicationController
   active_scaffold :transporte do |config|
    
    config.label = "Transportes Cancelados"
    
    config.columns = [:deposito, :box, :ndt, :transportadora, :uf, :pares, :cxs, :tipo, :m, :peso, :status, :data_inicio, :obs_trans  ]
    
    config.columns.add :etq
    
    config.create.columns = [:deposito, :tipo, :transportadora, :uf, :status,  :ndt, :pares, :cxs, :m, :peso]
    config.update.columns = [:deposito, :tipo, :transportadora, :uf, :status,  :ndt, :pares, :cxs, :m, :peso, :box, :obs_trans, :etiqueta]

    config.theme = :blue
    config.columns[:data_inicio].description = "Data da cria��o."
    config.columns[:ndt].description = "NUMERO DO DOCUMENTO DE TRANSPORTE."
    config.columns[:transportadora].description = "TRANSPORTADORA"
    config.columns[:uf].description = "DESTINO"
    config.columns[:pares].description = "QUANTIDADE DE PARES"
    config.columns[:cxs].description = "QUANTIDADE DE CAIXAS"
    config.columns[:tipo].description = "TIPO DE ENVIO"
    config.columns[:m].description = "VOLUME DA CARGA"
    config.columns[:peso].description = "PESO DA CARGA"
    config.columns[:box].description = "BOX"
    config.columns[:deposito].description = "DEPOSITO"
    config.columns[:status].description = "STATUS"
    #config.columns[:etiqueta].description = "ETIQUETA"
    config.columns[:obs_trans].description = "OBS. TRANSP."
    
    config.columns[:data_inicio].label = "DATA"
    config.columns[:ndt].label = "NDT."
    config.columns[:transportadora].label = "TRANSP."
    config.columns[:uf].label = "DESTINO"
    config.columns[:pares].label = "PARES"
    config.columns[:cxs].label = "CXS"
    config.columns[:tipo].label = "TIPO"
    config.columns[:m].label = "VOLUME"
    config.columns[:peso].label = "PESO"
    config.columns[:box].label = "BOX"
    config.columns[:deposito].label = "DEPOSITO"
    config.columns[:status].label = "STATUS"
    #config.columns[:etiqueta].label = "ETIQUETA"
    config.columns[:obs_trans].label = "OBS"
    
    config.columns[:tipo].ui_type = :select
    config.columns[:deposito].ui_type = :select
    config.columns[:transportadora].ui_type = :select    
    config.columns[:uf].ui_type = :select    
    config.columns[:status].ui_type = :select    
    
    config.list.sorting = {:deposito => 'ASC'}
    config.list.per_page = 100000
    
    config.create.link.label = "NOVO"
    config.search.link.label = "BUSCA"
    config.show.link.label = "Detalhes"
    config.delete.link.label = "Apagar"
    config.delete.link.confirm = "Apagar?"
    
    config.actions.exclude :create
  end
  
  def conditions_for_collection
    ['status_id = ? ','17']
  end
  
  protected
  
  def before_save(record,status)
    if record.status_id == Status.find(status)
      record.ended_at = DateTime.now
    end
  end
end
